package com.ruoyi.comn.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.comn.domain.ComnSalesperson;
import com.ruoyi.comn.service.IComnSalespersonService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 销售人员管理Controller
 * 
 * @author ruoyi
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/salesperson")
public class ComnSalespersonController extends BaseController
{
    @Autowired
    private IComnSalespersonService comnSalespersonService;

    /**
     * 查询销售人员管理列表
     */
    @PreAuthorize(hasPermi = "comn:salesperson:list")
    @GetMapping("/list")
    public TableDataInfo list(ComnSalesperson comnSalesperson)
    {
        startPage();
        List<ComnSalesperson> list = comnSalespersonService.selectComnSalespersonList(comnSalesperson);
        return getDataTable(list);
    }

    /**
     * 导出销售人员管理列表
     */
    @PreAuthorize(hasPermi = "comn:salesperson:export")
    @Log(title = "销售人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComnSalesperson comnSalesperson) throws IOException
    {
        List<ComnSalesperson> list = comnSalespersonService.selectComnSalespersonList(comnSalesperson);
        ExcelUtil<ComnSalesperson> util = new ExcelUtil<ComnSalesperson>(ComnSalesperson.class);
        util.exportExcel(response, list, "销售人员管理数据");
    }

    /**
     * 获取销售人员管理详细信息
     */
    @PreAuthorize(hasPermi = "comn:salesperson:query")
    @GetMapping(value = "/{salespersonUuid}")
    public AjaxResult getInfo(@PathVariable("salespersonUuid") String salespersonUuid)
    {
        return AjaxResult.success(comnSalespersonService.selectComnSalespersonBySalespersonUuid(salespersonUuid));
    }

    /**
     * 新增销售人员管理
     */
    @PreAuthorize(hasPermi = "comn:salesperson:add")
    @Log(title = "销售人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComnSalesperson comnSalesperson)
    {
        return toAjax(comnSalespersonService.insertComnSalesperson(comnSalesperson));
    }

    /**
     * 修改销售人员管理
     */
    @PreAuthorize(hasPermi = "comn:salesperson:edit")
    @Log(title = "销售人员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComnSalesperson comnSalesperson)
    {
        return toAjax(comnSalespersonService.updateComnSalesperson(comnSalesperson));
    }

    /**
     * 删除销售人员管理
     */
    @PreAuthorize(hasPermi = "comn:salesperson:remove")
    @Log(title = "销售人员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salespersonUuids}")
    public AjaxResult remove(@PathVariable String[] salespersonUuids)
    {
        return toAjax(comnSalespersonService.deleteComnSalespersonBySalespersonUuids(salespersonUuids));
    }
}
